home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / listbox / lbdemo / listdemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-03-15  |  6.5 KB  |  192 lines

  1. VERSION 2.00
  2. Begin Form frmListDemo 
  3.    Caption         =   "List Control Demo"
  4.    ClientHeight    =   4800
  5.    ClientLeft      =   2280
  6.    ClientTop       =   1650
  7.    ClientWidth     =   5760
  8.    Height          =   5265
  9.    Left            =   2190
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   4800
  12.    ScaleWidth      =   5760
  13.    Top             =   1275
  14.    Width           =   5940
  15.    Begin TextBox txtSearch 
  16.       Height          =   285
  17.       Left            =   240
  18.       TabIndex        =   1
  19.       Top             =   360
  20.       Width           =   5295
  21.    End
  22.    Begin CommandButton cmdExit 
  23.       Caption         =   "E&xit"
  24.       Height          =   495
  25.       Left            =   3000
  26.       TabIndex        =   8
  27.       Top             =   4080
  28.       Width           =   2535
  29.    End
  30.    Begin ListBox lstFonts 
  31.       Height          =   1200
  32.       Left            =   240
  33.       Sorted          =   -1  'True
  34.       TabIndex        =   6
  35.       Top             =   3360
  36.       Width           =   2535
  37.    End
  38.    Begin TextBox txtListHeadings 
  39.       BorderStyle     =   0  'None
  40.       Enabled         =   0   'False
  41.       ForeColor       =   &H00C00000&
  42.       Height          =   255
  43.       Left            =   240
  44.       MultiLine       =   -1  'True
  45.       TabIndex        =   4
  46.       Text            =   "(headings)"
  47.       Top             =   1440
  48.       Width           =   855
  49.    End
  50.    Begin CommandButton cmdSetColumns 
  51.       Caption         =   "(set columns)"
  52.       Height          =   495
  53.       Left            =   3000
  54.       TabIndex        =   7
  55.       Top             =   3480
  56.       Width           =   2535
  57.    End
  58.    Begin ListBox lstFruits 
  59.       FontBold        =   -1  'True
  60.       FontItalic      =   0   'False
  61.       FontName        =   "MS Sans Serif"
  62.       FontSize        =   9.75
  63.       FontStrikethru  =   0   'False
  64.       FontUnderline   =   0   'False
  65.       Height          =   1230
  66.       Left            =   240
  67.       Sorted          =   -1  'True
  68.       TabIndex        =   5
  69.       Top             =   1800
  70.       Width           =   5295
  71.    End
  72.    Begin ComboBox cboSelect 
  73.       Height          =   300
  74.       Left            =   240
  75.       Sorted          =   -1  'True
  76.       Style           =   2  'Dropdown List
  77.       TabIndex        =   3
  78.       Top             =   1080
  79.       Width           =   5295
  80.    End
  81.    Begin Label lblSearch 
  82.       Caption         =   "Search:"
  83.       Height          =   255
  84.       Left            =   240
  85.       TabIndex        =   0
  86.       Top             =   120
  87.       Width           =   1455
  88.    End
  89.    Begin Label lblSelect 
  90.       Caption         =   "Select:"
  91.       Height          =   255
  92.       Left            =   240
  93.       TabIndex        =   2
  94.       Top             =   840
  95.       Width           =   1455
  96.    End
  97. Option Explicit
  98. 'If you have questions, comments, or suggestions for
  99. 'improving the code presented here, please forward them
  100. 'to me; you're input is welcome:
  101. '        Brad Kaenel
  102. '        PC HELP-LINE
  103. '        35250 Silver Leaf Circle
  104. '        Yucaipa, CA  92399
  105. '        United States
  106. '        CIS: 72357,3523
  107. '        Internet: 72357.3523@compuserve.com
  108. 'Although multi-column listboxes are a common
  109. 'requirement, they are difficult to accomplish
  110. 'in VB.
  111. 'A simple solution is to select a mono-spaced
  112. 'font for the listbox and align the data manually,
  113. 'but this is not always visually appealing.  However,
  114. 'with a little more work you can set dynamic tabstops
  115. 'that will work with proportional fonts.
  116. 'This sample demonstrates how to set tabstops in a listbox,
  117. 'using a borderless, disabled text box for the column
  118. 'headings.  It also shows how to "pre-select" a listbox
  119. 'or combobox item, using Windows API functions.
  120. Dim sFruit(10) As String, sMyFruit As String
  121. Dim nTabStopsSet As Integer
  122. Sub cboSelect_Click ()
  123. sMyFruit = cboSelect.Text
  124. txtSearch.Text = sMyFruit
  125. Call SelectFruit  'synchronize the listbox
  126. End Sub
  127. Sub cmdExit_Click ()
  128. Unload frmListDemo
  129. End Sub
  130. Sub cmdSetColumns_Click ()
  131. Call SetTabStops
  132. End Sub
  133. Sub Form_Load ()
  134. Dim nFruitCount As Integer
  135. 'load up some multi-column data
  136. txtListHeadings.Text = "Fruit" + Chr$(9) + "Opinion" + Chr$(9) + "Color"
  137. sFruit(1) = "Oranges" + Chr$(9) + "Good" + Chr$(9) + "Orange, of course"
  138. sFruit(2) = "Bananas" + Chr$(9) + "Munchy" + Chr$(9) + "Yellow"
  139. sFruit(3) = "Apples" + Chr$(9) + "Delicious" + Chr$(9) + "Red"
  140. sFruit(4) = "Blueberries" + Chr$(9) + "Nah" + Chr$(9) + "Blue"
  141. sFruit(5) = "Plums" + Chr$(9) + "Better than prunes" + Chr$(9) + "Purple"
  142. sFruit(6) = "Watermelons" + Chr$(9) + "Marvelous" + Chr$(9) + "Red and Green"
  143. sFruit(7) = "Cherries" + Chr$(9) + "Ummm..." + Chr$(9) + "Bright Red"
  144. sFruit(8) = "Mangos" + Chr$(9) + "Juicy" + Chr$(9) + "No idea"
  145. sFruit(9) = "Kiwis" + Chr$(9) + "Kinda weird" + Chr$(9) + "Fuzzy Green"
  146. sFruit(10) = "Peaches" + Chr$(9) + "OK" + Chr$(9) + "Peach, I guess(?)"
  147. For nFruitCount = 1 To UBound(sFruit)
  148.    lstFruits.AddItem sFruit(nFruitCount)
  149.    'comboboxes don't support columns, so only use first string
  150.    cboSelect.AddItem Left$(sFruit(nFruitCount), InStr(sFruit(nFruitCount), Chr$(9)) - 1)
  151. For nFruitCount = 0 To Screen.FontCount - 1
  152.    lstFonts.AddItem Screen.Fonts(nFruitCount)
  153. nTabStopsSet = True
  154. cmdSetColumns.Value = True  'trigger tab stops
  155. End Sub
  156. Sub lstFonts_Click ()
  157. lstFruits.FontName = lstFonts.List(lstFonts.ListIndex)
  158. lstFruits.Height = (lstFonts.Top - lstFruits.Top) - 20
  159. nTabStopsSet = Not nTabStopsSet
  160. cmdSetColumns.Value = True  'trigger tab stops
  161. End Sub
  162. Sub lstFruits_Click ()
  163. sMyFruit = lstFruits.Text
  164. If Len(sMyFruit) > 0 Then
  165.    sMyFruit = Left$(sMyFruit, InStr(sMyFruit, Chr$(9)) - 1)
  166.    txtSearch.Text = sMyFruit
  167.    Call SelectFruit  'synchronize the combobox
  168. End If
  169. End Sub
  170. Sub SelectFruit ()
  171. If tfDULIST_SelectListItem(lstFruits, sMyFruit) Then
  172.    If tfDULIST_SelectListItem(cboSelect, sMyFruit) Then
  173.    End If
  174. End If
  175. End Sub
  176. Sub SetTabStops ()
  177. If nTabStopsSet Then
  178.    If tfDULIST_SetListCols(lstFruits, txtListHeadings, False, True) Then
  179.       cmdSetColumns.Caption = "Set &Custom Tab Stops"
  180.       nTabStopsSet = Not nTabStopsSet
  181.    End If
  182.    If tfDULIST_SetListCols(lstFruits, txtListHeadings, False, False) Then
  183.       cmdSetColumns.Caption = "Reset &Default Tab Stops"
  184.       nTabStopsSet = Not nTabStopsSet
  185.    End If
  186. End If
  187. End Sub
  188. Sub txtSearch_Change ()
  189. sMyFruit = txtSearch.Text
  190. Call SelectFruit  'synchronize the listbox and combobox
  191. End Sub
  192.